package com.xhb.biz.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.solon.service.impl.ServiceImpl;
import com.xhb.biz.mapper.UrlMapper;
import com.xhb.biz.po.UrlPO;
import org.noear.solon.aspect.annotation.Service;
import org.noear.solon.data.annotation.Tran;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class UrlService extends ServiceImpl<UrlMapper, UrlPO> {

    public List<UrlPO> getUrlList() {
        List<UrlPO> list = super.list();
        return list;
    }

    @Tran
    public void syncUrlData(List<UrlPO> pos) {
        super.saveOrUpdateBatch(pos);
        // 删除已被管理端删除的旧数据
        LambdaQueryWrapper<UrlPO> delWrapper = new LambdaQueryWrapper<>();
        delWrapper.notIn(UrlPO::getId, pos.stream().map(UrlPO::getId).collect(Collectors.toList()));
        super.remove(delWrapper);
    }
}
